/*
 * obj.h -- obj model loader
 *
 * Copyright (c) 2005-2007 David HENRY
 *
 * Permission is hereby granted, free of charge, to any person
 * obtaining a copy of this software and associated documentation
 * files (the "Software"), to deal in the Software without
 * restriction, including without limitation the rights to use,
 * copy, modify, merge, publish, distribute, sublicense, and/or
 * sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT.
 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
 * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 *
 */

#ifndef _OBJ_H
#define _OBJ_H

#ifdef __cplusplus
extern "C" {
#endif

#include "../../math/src/mgpi_math.h"

#pragma pack(push,1)

    /* Polygon */
    struct obj_face_t {
        int type; /* primitive type */
        int num_elems; /* number of vertices */

        int *vert_indices; /* vertex indices */
        int *uvw_indices; /* texture coordinate indices */
        int *norm_indices; /* normal vector indices */
    };

    /* OBJ static model structure */
    typedef struct _obj_model_t {
        int num_verts; /* number of vertices */
        int num_texCoords; /* number of texture coords. */
        int num_normals; /* number of normal vectors */
		int num_indices;
        int num_faces; /* number of polygons */

        int has_texCoords; /* has texture coordinates? */
        int has_normals; /* has normal vectors? */
		int gen_normals;

        float4 *vertices; /* vertex list */
        float3 *texCoords[16]; /* tex. coord. list array */
        float3 *normals[3]; /* normal vector list array (tangent, binormal and normal) */
        struct obj_face_t *faces; /* model's polygons */
		GLuint *indices;  
		int tex_id;
    } obj_model_t;

	typedef struct _joint {
		float *transformation;
		struct _joint *parent;
	} joint_t;

#pragma pack(pop)

    void MGPI_API gsubFreeOBJModel(obj_model_t *mdl);
    int MGPI_API gsubReadOBJModel(const char *name, obj_model_t *mdl);
    void MGPI_API gsubRenderOBJModel(obj_model_t *mdl);
	void MGPI_API gsubMapAttributes(obj_model_t *mdl, float *attribs, ...);

#ifdef __cplusplus
}
#endif

#endif
